package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysProject2;
import com.ruoyi.system.service.ISysProject2Service;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 项目Controller
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/system/project2")
public class SysProject2Controller extends BaseController
{
    @Autowired
    private ISysProject2Service sysProject2Service;

    /**
     * 
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project2:list')")
    @GetMapping("/list")
    public AjaxResult list(SysProject2 sysProject2)
    {
        List<SysProject2> list = sysProject2Service.selectSysProject2List(sysProject2);
        return success(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project2:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProject2 sysProject2)
    {
        List<SysProject2> list = sysProject2Service.selectSysProject2List(sysProject2);
        ExcelUtil<SysProject2> util = new ExcelUtil<SysProject2>(SysProject2.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:project2:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(sysProject2Service.selectSysProject2ByProjectId(projectId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('system:project2:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProject2 sysProject2)
    {
        return toAjax(sysProject2Service.insertSysProject2(sysProject2));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('system:project2:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProject2 sysProject2)
    {
        return toAjax(sysProject2Service.updateSysProject2(sysProject2));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('system:project2:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(sysProject2Service.deleteSysProject2ByProjectIds(projectIds));
    }
}
